[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
perror() Print Error Message
#include <stdio.h> Required for declarations only
void perror(string);
const char *string; User-supplied message
int errno; Error number
int sys_nerr; Number of system messages
char sys_errlist[sys_nerr]; Array of error messages
perror() prints an error message to 'stderr'. In order, perror()
prints:
the user-supplied 'string' argument,
a colon,
system error message for last library call that produced an
error,
a new-line character.
System error messages are accessed through an array of messages,
ordered by 'errno', called 'sys_errlist'. The error number generated
by the most recent system call is stored in the external variable
'errno' (which should be declared at the external level). 'errno'
reflects the most recent error generated by a system library call in
the current program. perror() uses 'errno' as an index to
sys_errlist to print the appropriate error message. 'sys_nerr'
contains the maximum number of elements in 'sys_errlist'.
Returns: Nothing
Notes: Call perror() immediately after the system call returns
with an error. Otherwise, the error number in 'errno' may
be overwritten by an error generated by a subsequent
system call.
-------------------------------- Example ---------------------------------
#include <fcntl.h> /* constants defined */
#include <sys\stat.h> /* constants defined */
#include <io.h> /* for open */
#include <stdio.h>
int fhndl;
main()
{
if ((fhndl = open("inp.dat",O_RDONLY)) == -1)
perror("unable to open file");
}
See Also:
clearerr()
ferror()
strerror()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson